﻿#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<graphics.h>
#include<stdlib.h>
#include<ege.h>
#include<Windows.h>
#include <conio.h>
#include <cmath>

#define PI 3.1415926
#define JIAODU 1080

static double len = 1000;// 定义图形大小
static double x = 0, y = 0;
double jiaodu1 = 0;
double jiaodu2 = 0;
double jiaodu3 = 180.0;
int j = 0;

//按钮结构体
typedef struct Button
{
	float x;
	float y;
	float radius;//半径
	bool press;//状态
} Button;


typedef struct PROP {
	//圆心
	ege_point round;
	//屏幕分辨率
	ege_point scr;
	//刻度半径
	float radius;
	//刻度线长度
	float caliLeng;
	//刻度坐标
	ege_point pStart[JIAODU];
	ege_point pEnd[JIAODU];

	PIMAGE img[JIAODU];
}PROP;

PROP prop;

static inline int  GetScrX() { return GetSystemMetrics(SM_CXSCREEN); }
static inline int  GetScrY() { return GetSystemMetrics(SM_CYSCREEN); }

//判断左旋钮是否被点击
bool isPressOnButton1(const Button* button, int x, int y)
{
	float dx = x - button->x;
	float dy = y - button->y;
	return (dx * dx + dy * dy) <= (button->radius * button->radius);
}

//判断右旋钮是否被点击
bool isPressOnButton2(const Button* button, int x, int y)
{
	float dx = x - button->x;
	float dy = y - button->y;
	return (dx * dx + dy * dy) <= (button->radius * button->radius);
}

void Init() {
	//初始化数据
	initgraph(len, len, INIT_RENDERMANUAL);
	setbkcolor(EGERGB(22, 22, 22));
	ege_setalpha(255);
	ege_enable_aa(true);
	setcolor(EGEARGB(0xFF, 220, 220, 220));
	//设置分辨率
	prop.scr.x = len;
	prop.scr.y = len;
	//设置圆心
	prop.round.y = prop.scr.y / 2.0;
	prop.round.x = prop.scr.x / 2.0;
	//设定半径
	prop.radius = len / 3.04347826;
	//设定刻度线长度
	prop.caliLeng = prop.scr.y / 20.0;
	//设定刻度坐标
	float r = 0.0;
	for (; r < JIAODU; r = r + 1.0) {

		prop.pStart[int(r)].x = prop.round.x + prop.radius * cos(r * 1.0 * PI / (JIAODU / 2.0)) * 1.1;
		prop.pStart[int(r)].y = prop.round.y + prop.radius * sin(r * 1.0 * PI / (JIAODU / 2.0)) * 1.1;
		prop.pEnd[int(r)].x = prop.round.x + (prop.radius - prop.scr.y / 40.0) * cos(r * 1.0 * PI / (JIAODU / 2.0));
		prop.pEnd[int(r)].y = prop.round.y + (prop.radius - prop.scr.y / 40.0) * sin(r * 1.0 * PI / (JIAODU / 2.0));
	}
}

void InitNumber()
{
	char n = 'N';
	char e = 'E';
	char s = 'S';
	char w = 'W';
	char u = ' ';
	setfont(prop.scr.y / 25.0, 0, "宋体");
	for (int i = 0; i < JIAODU; i++)
	{
		if (i == 0) {
			xyprintf(prop.scr.y / 25.0, prop.scr.y / 25.0, "%c ", n);
		}
		else if (i == 15 * (JIAODU / 360.0)) {
			xyprintf(prop.scr.y / 25.0, prop.scr.y / 25.0, "%c ", e);
		}
		else if (i == 30 * (JIAODU / 360.0)) {
			xyprintf(prop.scr.y / 25.0, prop.scr.y / 25.0, "%c ", s);
		}
		else if (i == 45 * (JIAODU / 360.0)) {
			xyprintf(prop.scr.y / 25.0, prop.scr.y / 25.0, "%c ", w);
		}
		else if (
			i == 5 * (JIAODU / 360.0) ||
			i == 10 * (JIAODU / 360.0) ||
			i == 20 * (JIAODU / 360.0) ||
			i == 25 * (JIAODU / 360.0) ||
			i == 35 * (JIAODU / 360.0) ||
			i == 40 * (JIAODU / 360.0) ||
			i == 50 * (JIAODU / 360.0) ||
			i == 55 * (JIAODU / 360.0)
			) {
			xyprintf(prop.scr.y / 25.0, prop.scr.y / 25.0, "%d", i * (6 / (JIAODU / 360)));
		}
		else xyprintf(prop.scr.y / 25.0, prop.scr.y / 25.0, "%c", u);
		prop.img[i] = newimage();
		getimage(prop.img[i], prop.scr.y / 25.0, prop.scr.y / 25.0,
			prop.scr.y / 25.0, prop.scr.y / 25.0);
		//delimage(prop.img[i]);
	}
}

void DrawSecLine(float sec)
{
	ege_enable_aa(true);
	for (int i = JIAODU - 1; i >= 0; i--)
	{
		if ((i + JIAODU - ((int)(sec * 6.0))) % (5 * (JIAODU / 360)) == 0)
		{
			ege_line(prop.pStart[i].x, prop.pStart[i].y, prop.pEnd[i].x, prop.pEnd[i].y);
			if ((i + 360 - ((int)(sec * 6.0))) % (30 * (JIAODU / 360)) == 0) {
				putimage_rotate(NULL, prop.img[((i / 6) + 15 - (int)(sec)+60) % (60 * (JIAODU / 360))],
					prop.pEnd[i].x, prop.pEnd[i].y, 0.5f, 0.5f,
					((float(-i)) + JIAODU * 0.75) * PI / (JIAODU / 2.0),
					EGEARGB(0xAF, 200, 200, 200));
			}
		}
	}
}

void DrawCompass()
{
	//圆形罗盘
	ege_enable_aa(true);
	setfillcolor(EGEACOLOR(0xA0, 0, 0, 0));
	ege_fillellipse(len / 7.36842105, len / 7.36842105, len / 1.37254901, len / 1.37254901);
}

void DrawScale()
{
	//外刻度

	//左上
	ege_enable_aa(true);
	int numPoints5 = 4;
	ege_point  polyPoints5[4] =
	{
		{len / 5.93220338,len / 5.93220338},
		{len / 4.375,len / 4.375},
		{len / 4.45859872,len / 4.32098765},
		{len / 5.93220338,len / 5.69105691}
	};
	setfillcolor(EGEARGB(0xAF, 200, 200, 200));
	ege_fillpoly(numPoints5, polyPoints5);
	//右上
	int numPoints6 = 4;
	ege_point  polyPoints6[4] =
	{
		{len / 1.20274914,len / 5.93220338},
		{len / 1.29629629,len / 4.375},
		{len / 1.28913443,len / 4.32098765},
		{len / 1.20274914,len / 5.69105691}
	};
	setfillcolor(EGEARGB(0xAF, 200, 200, 200));
	ege_fillpoly(numPoints6, polyPoints6);
	//左下
	int numPoints7 = 4;
	ege_point  polyPoints7[4] =
	{
		{len / 5.93220338,len / 1.20274914},
		{len / 4.375,len / 1.29629629},
		{len / 4.45859872,len / 1.30111524},
		{len / 5.93220338,len / 1.21317157}
	};
	setfillcolor(EGEARGB(0xAF, 200, 200, 200));
	ege_fillpoly(numPoints7, polyPoints7);
	//右下
	int numPoints8 = 4;
	ege_point  polyPoints8[4] =
	{
		{len / 1.20274914,len / 1.20274914},
		{len / 1.29629629,len / 1.29629629},
		{len / 1.28913443,len / 1.30111524},
		{len / 1.20274914,len / 1.21317157}
	};
	setfillcolor(EGEARGB(0xAF, 200, 200, 200));
	ege_fillpoly(numPoints8, polyPoints8);
	//下中
	int numPoints9 = 4;
	ege_point  polyPoints9[4] =
	{
		{len / 1.98863636,len / 1.13821138},
		{len / 1.98863636,len / 1.07692307},
		{len / 2.01149425,len / 1.07692307},
		{len / 2.01149425,len / 1.13821138}
	};
	setfillcolor(EGEARGB(0xAF, 200, 200, 200));
	ege_fillpoly(numPoints9, polyPoints9);
	//上中
	int numPoints10 = 6;
	ege_point  polyPoints10[6] = {
		{len / 1.94444444,len / 14.0},
		{len / 1.98300283,len / 10.76923076},
		{len / 1.98300283,len / 4.375},
		{len / 2.01729106,len / 4.375},
		{len / 2.01729106,len / 10.76923076},
		{len / 2.05882352,len / 14.0}
	};
	setfillcolor(EGEARGB(0xAF, 200, 200, 200));
	ege_fillpoly(numPoints10, polyPoints10);
}

//void DrawPointer()
//{
//	//指针
//	ege_enable_aa(true);
//	int numPoints3 = 7;
//	ege_point  polyPoints3[7] =
//	{
//		{len / 2.0,len / 5.83333333},		//350,120
//		{len / 1.94444444,len / 5.6},		//360,125
//		{len / 1.98863636,len / 5.6},		//352,125
//		{len / 1.98863636,len / 1.20689655},//352,580
//		{len / 2.01149425,len / 1.20689655},//348,580
//		{len / 2.01149425,len / 5.6},		//348,125
//		{len / 2.05882352,len / 5.6}		//340,125
//	};
//	setfillcolor(EGEARGB(0xFF, 118, 104, 18, ));
//	ege_fillpoly(numPoints3, polyPoints3);
//}

void DrawPointer()
{
	//指针
	ege_enable_aa(true);
	int numPoints3 = 7;

	double x2 = len / 2.0;
	double y2 = len / 2.0;
	ege_point  polyPoints3[7] =
	{

		{(len / 2.0 - x2) * cos(PI / 180.0 * jiaodu1) - (len / 5.83333333 - y2) * sin(PI / 180.0 * jiaodu1) + x2, (len / 2.0 - x2) * sin(PI / 180.0 * jiaodu1) + (len / 5.83333333 - y2) * cos(PI / 180.0 * jiaodu1) + y2},		//350,120
		{(len / 1.94444444 - x2) * cos(PI / 180.0 * jiaodu1) - (len / 5.6 - y2) * sin(PI / 180.0 * jiaodu1) + x2, (len / 1.94444444 - x2) * sin(PI / 180.0 * jiaodu1) + (len / 5.6 - y2) * cos(PI / 180.0 * jiaodu1) + y2},		//360,125
		{(len / 1.98863636 - x2) * cos(PI / 180.0 * jiaodu1) - (len / 5.6 - y2) * sin(PI / 180.0 * jiaodu1) + x2, (len / 1.98863636 - x2) * sin(PI / 180.0 * jiaodu1) + (len / 5.6 - y2) * cos(PI / 180.0 * jiaodu1) + y2},		//352,125
		{(len / 1.98863636 - x2) * cos(PI / 180.0 * jiaodu1) - (len / 1.20689655 - y2) * sin(PI / 180.0 * jiaodu1) + x2, (len / 1.98863636 - x2) * sin(PI / 180.0 * jiaodu1) + (len / 1.20689655 - y2) * cos(PI / 180.0 * jiaodu1) + y2},//352,580
		{(len / 2.01149425 - x2) * cos(PI / 180.0 * jiaodu1) - (len / 1.20689655 - y2) * sin(PI / 180.0 * jiaodu1) + x2, (len / 2.01149425 - x2) * sin(PI / 180.0 * jiaodu1) + (len / 1.20689655 - y2) * cos(PI / 180.0 * jiaodu1) + y2},//348,580
		{(len / 2.01149425 - x2) * cos(PI / 180.0 * jiaodu1) - (len / 5.6 - y2) * sin(PI / 180.0 * jiaodu1) + x2, (len / 2.01149425 - x2) * sin(PI / 180.0 * jiaodu1) + (len / 5.6 - y2) * cos(PI / 180.0 * jiaodu1) + y2},		//348,125
		{(len / 2.05882352 - x2) * cos(PI / 180.0 * jiaodu1) - (len / 5.6 - y2) * sin(PI / 180.0 * jiaodu1) + x2, (len / 2.05882352 - x2) * sin(PI / 180.0 * jiaodu1) + (len / 5.6 - y2) * cos(PI / 180.0 * jiaodu1) + y2}		//340,125
	};
	setfillcolor(EGEARGB(0xFF, 118, 104, 18, ));
	ege_fillpoly(numPoints3, polyPoints3);
}

void DrawPlane()
{
	//飞机
	ege_enable_aa(true);
	int numPoints2 = 16;
	ege_point  polyPoints2[16] =
	{
		{len / 2.02898550,len / 2.25806451},
		{len / 1.97183098,len / 2.25806451},
		{len / 1.97183098,len / 2.0},
		{len / 1.75,len / 2.0},
		{len / 1.75,len / 1.94444444},
		{len / 1.97183098,len / 1.94444444},
		{len / 1.97183098,len / 1.84210526},
		{len / 1.89189189,len / 1.84210526},
		{len / 1.89189189,len / 1.79487179},
		{len / 2.12121212,len / 1.79487179},
		{len / 2.12121212,len / 1.84210526},
		{len / 2.02898550,len / 1.84210526},
		{len / 2.02898550,len / 1.94444444},
		{len / 2.33333333,len / 1.94444444},
		{len / 2.33333333,len / 2.0},
		{len / 2.02898550,len / 2.0}
	};
	setfillcolor(EGEARGB(0xFF, 132, 84, 22, ));
	ege_fillpoly(numPoints2, polyPoints2);
}

void DrawMAU()
{
	//MAU红色字块
	ege_enable_aa(true);
	int numPoints0 = 4;
	ege_point  polyPoints0[4] =
	{
		{len / 4.66666666,len / 5.38461538},
		{len / 2.97872340,len / 5.38461538},
		{len / 2.97872340,len / 4.11764705},
		{len / 4.66666666,len / 4.11764705}
	};
	setfillcolor(EGEARGB(0xFF, 123, 18, 18, ));
	ege_fillpoly(numPoints0, polyPoints0);
	setbkmode(TRANSPARENT);			//设置文字背景色为透明
	setcolor(EGERGB(140, 141, 17));
	setfont(len / 20.0, 0, "楷体", 0, 0, 0, false, false, false);
	outtextxy(len / 4.24242424, len / 5.38461538, "MAU");
}

void DrawGS()
{
	//GS红色字块(右)
	ege_enable_aa(true);
	int numPoints1 = 4;
	ege_point  polyPoints1[4] =
	{
		{len / 1.15702479,len / 3.5},
		{len / 1.06060606,len / 3.5},
		{len / 1.06060606,len / 1.4},
		{len / 1.15702479,len / 1.4}
	};
	setfillcolor(EGEARGB(0xFF, 123, 18, 18, ));
	ege_fillpoly(numPoints1, polyPoints1);
	setbkmode(TRANSPARENT);			//设置文字背景色为透明
	setcolor(EGERGB(140, 141, 17));
	setfont(len / 20.0, 0, "楷体", 0, 0, 0, false, false, false);
	outtextxy(len / 1.12903225, len / 2.1875, "G");
	outtextxy(len / 1.12903225, len / 2.0, "S");
	//GS红色字块(左)
	int numPoints4 = 4;
	ege_point  polyPoints4[4] =
	{
		{len / 7.36842105,len / 3.5},
		{len / 17.5,len / 3.5},
		{len / 17.5,len / 1.4},
		{len / 7.36842105,len / 1.4}
	};
	setfillcolor(EGEARGB(0xFF, 123, 18, 18, ));
	ege_fillpoly(numPoints4, polyPoints4);
	setbkmode(TRANSPARENT);			//设置文字背景色为透明
	setcolor(EGERGB(140, 141, 17));
	setfont(len / 20.0, 0, "楷体", 0, 0, 0, false, false, false);
	outtextxy(len / 12.72727272, len / 2.1875, "G");
	outtextxy(len / 12.72727272, len / 2.0, "S");
}

void DrawInnerborder()
{
	//内边框
	ege_enable_aa(true);
	ege_point points[] = {
	{len / 2.0,len / 12.72727272},
	{len / 1.34615384,len / 10.0},
	{len / 1.12903225,len / 3.88888888},
	{len / 1.04477611,len / 2.0},
	{len / 1.12903225,len / 1.37254901},
	{len / 1.42857142,len / 1.12},
	{len / 2.0,len / 1.09375},
	{len / 3.33333333,len / 1.12},
	{len / 8.75,len / 1.37254901},
	{len / 23.33333333,len / 2.0},
	{len / 8.75,len / 3.88888888},
	{len / 3.88888888,len / 10.0},
	{len / 2.0,len / 12.72727272},
	};
	setcolor(EGERGB(0xAF, 200, 200, 200));
	ege_drawcurve(13, points);
}

void DrawBoundary()
{
	//屏幕边界
	ege_enable_aa(true);
	setcolor(EGERGB(0xAF, 200, 200, 200));
	ege_rectangle(-3, -3, len + 5, len + 5);
}

void DrawMargin()
{
	//外边框
	ege_enable_aa(true);
	for (int i = 0; i < (int)(len / 53.846); i++) {											// 外框：弧线
		setcolor(EGERGB(75 + 10 * i, 75 + 10 * i, 75 + 10 * i, 255));
		ege_arc(-(len / 14 * 3) + x, y + i, (len / 7 * 10), (len / 7 * 10), 240, 60);
		ege_arc(x + i, -(len / 14 * 3) + y, (len / 7 * 10), (len / 7 * 10), 150, 60);
		ege_arc(-(len / 14 * 3) + x, -(len / 14 * 6) + y - i, (len / 7 * 10), (len / 7 * 10), 60, 60);
		ege_arc(-(len / 14 * 6) + x - i, -(len / 14 * 3) + y, (len / 7 * 10), (len / 7 * 10), 330, 60);
	}
	for (int i = 0; i < (int)(len / 53.846); i++) {											// 外框：直线
		setcolor(EGERGB(75 + 10 * i, 75 + 10 * i, 75 + 10 * i, 255));
		ege_line((len / 7.000) + x, (len / 10.447761194) + y + i, (len / 10.447761194) + x + i, (len / 7.000) + y);
		ege_line((len / 1.166666667) + x, (len / 10.447761194) + y + i, (len / 1.10584518) + x - i, (len / 7.000) + y);
		ege_line((len / 7.000) + x, (len / 1.10584518) + y - i, (len / 10.447761194) + x + i, (len / 1.166666667) + y);
		ege_line((len / 1.10584518) + x - i, (len / 1.166666667) + y, (len / 1.166666667) + x, (len / 1.10584518) + y - i);
	}
}


void DrawWhiteGS()
{
	//白色左GS
	ege_enable_aa(true);
	setcolor(EGERGB(150, 150, 150, 255));
	setfont(len / 25.0, 0, "幼圆", 0, 0, 0, false, false, false);
	outtextxy(len / 6.36363636, len / 4.66666666, "GS");
	//白色右GS
	setcolor(EGERGB(150, 150, 150, 255));
	setfont(len / 25.0, 0, "幼圆", 0, 0, 0, false, false, false);
	outtextxy(len / 1.25, len / 4.66666666, "GS");
}

void DrawFill1()
{
	//区域填充
	ege_enable_aa(true);
	setfillcolor(RGB(38, 38, 38));
	floodfill(len / 2.0, len / 23.33333333, EGERGB(0xAF, 200, 200, 200));
}


void DrawBENDIXIKING()
{
	// 打印字母设置
	ege_enable_aa(true);
	setcolor(EGERGB(150, 150, 150, 255));
	setfont(len / 28.0, 0, "幼圆", 0, 0, 0, true, false, false);
	outtextxy(len / 2.54545454, len / 1.07692307, "BENDIXIKING");
}

void DisplaymMouseCoordinates()
{
	//显示鼠标坐标
	setfont(18, 0, "宋体");
	int k = 0;
	for (; is_run(); delay_fps(60))
	{
		char str[32];
		int x, y;

		//获取鼠标坐标，此函数不等待。若鼠标移出了窗口，那么坐标值不会更新
		//特殊情况是，你按着鼠标键不放，拖出窗口，这样坐标值会依然更新
		mousepos(&x, &y);

		//格式化输出为字符串，用于后面输出
		sprintf(str, "%4d %4d", x, y);
		outtextxy(0, 0, str);
	}
}

void DrawKnob()
{
	//左旋钮第一次
	ege_enable_aa(true);
	setfillcolor(EGERGB(18, 20, 22));
	ege_fillellipse(len / 17.5, len / 1.27272727, len / 7.36842105, len / 7.36842105);
	setcolor(WHITE);
	ege_ellipse(len / 21.21212121, len / 1.21739130, len / 7.36842105, len / 7.36842105);
	setfillcolor(EGERGB(30, 30, 30));
	ege_fillellipse(len / 20.58823529, len / 1.21527777, len / 7.52688172, len / 7.52688172);
	//右旋钮第一次
	setfillcolor(EGERGB(18, 20, 22));
	ege_fillellipse(len / 1.23893805, len / 1.27272727, len / 7.36842105, len / 7.36842105);
	setcolor(WHITE);
	ege_ellipse(len / 1.22377622, len / 1.21739130, len / 7.36842105, len / 7.36842105);
	setfillcolor(EGERGB(30, 30, 30));
	ege_fillellipse(len / 1.22164048, len / 1.21527777, len / 7.52688172, len / 7.52688172);

}


void DrawFill2()
{
	//按钮区域填充
	ege_enable_aa(true);
	setfillcolor(EGERGB(18, 20, 22));
	floodfill(len / 10.0, len / 1.23893805, WHITE);
	setfillcolor(EGERGB(18, 20, 22));
	floodfill(len / 1.11111111, len / 1.23893805, WHITE);
}


//void DrawButtonArrows()
//{
//	//左旋钮黄色箭头
//	ege_enable_aa(true);
//	int numPoints11 = 7;
//	ege_point  polyPoints11[7] = {
//		{len / 8.75,len / 1.20689655},			//(80,580)
//		{len / 8.23529411,len / 1.14754098},	//(85,610)
//		{len / 8.53658536,len / 1.14754098},	//(82,610)
//		{len / 8.53658536,len / 1.06060606},	//(82,660)
//		{len / 8.97435897,len / 1.06060606},	//(78,660)
//		{len / 8.97435897,len / 1.14754098},	//(78,610)
//		{len / 9.33333333,len / 1.14754098},	//(75,610)
//	};
//	setfillcolor(YELLOW);
//	ege_fillpoly(numPoints11, polyPoints11);
//}

void DrawButtonArrows()
{
	//左旋钮黄色箭头
	ege_enable_aa(true);
	int numPoints11 = 7;

	double x2 = len / 8.75;
	double y2 = len / 1.12903225;
	ege_point  polyPoints11[7] = {
		{(len / 8.75 - x2) * cos(PI / 180.0 * jiaodu1) - (len / 1.20689655 - y2) * sin(PI / 180.0 * jiaodu1) + x2, (len / 8.75 - x2) * sin(PI / 180.0 * jiaodu1) + (len / 1.20689655 - y2) * cos(PI / 180.0 * jiaodu1) + y2},
		{(len / 8.23529411 - x2) * cos(PI / 180.0 * jiaodu1) - (len / 1.14754098 - y2) * sin(PI / 180.0 * jiaodu1) + x2, (len / 8.23529411 - x2) * sin(PI / 180.0 * jiaodu1) + (len / 1.14754098 - y2) * cos(PI / 180.0 * jiaodu1) + y2},
		{(len / 8.53658536 - x2) * cos(PI / 180.0 * jiaodu1) - (len / 1.14754098 - y2) * sin(PI / 180.0 * jiaodu1) + x2, (len / 8.53658536 - x2) * sin(PI / 180.0 * jiaodu1) + (len / 1.14754098 - y2) * cos(PI / 180.0 * jiaodu1) + y2},
		{(len / 8.53658536 - x2) * cos(PI / 180.0 * jiaodu1) - (len / 1.06060606 - y2) * sin(PI / 180.0 * jiaodu1) + x2, (len / 8.53658536 - x2) * sin(PI / 180.0 * jiaodu1) + (len / 1.06060606 - y2) * cos(PI / 180.0 * jiaodu1) + y2},
		{(len / 8.97435897 - x2) * cos(PI / 180.0 * jiaodu1) - (len / 1.06060606 - y2) * sin(PI / 180.0 * jiaodu1) + x2, (len / 8.97435897 - x2) * sin(PI / 180.0 * jiaodu1) + (len / 1.06060606 - y2) * cos(PI / 180.0 * jiaodu1) + y2},
		{(len / 8.97435897 - x2) * cos(PI / 180.0 * jiaodu1) - (len / 1.14754098 - y2) * sin(PI / 180.0 * jiaodu1) + x2, (len / 8.97435897 - x2) * sin(PI / 180.0 * jiaodu1) + (len / 1.14754098 - y2) * cos(PI / 180.0 * jiaodu1) + y2},
		{(len / 9.33333333 - x2) * cos(PI / 180.0 * jiaodu1) - (len / 1.14754098 - y2) * sin(PI / 180.0 * jiaodu1) + x2, (len / 9.33333333 - x2) * sin(PI / 180.0 * jiaodu1) + (len / 1.14754098 - y2) * cos(PI / 180.0 * jiaodu1) + y2},
	};
	setfillcolor(YELLOW);
	ege_fillpoly(numPoints11, polyPoints11);
}

//void DrawHouse()
//{
//	//右旋钮橙色房子
//	ege_enable_aa(true);
//	int numPoints12 = 8;
//	ege_point  polyPoints12[8] = {
//		{len / 1.12903225,len / 1.18644067},	(620,590)
//		{len / 1.10236220,len / 1.14754098},	(635,610)
//		{len / 1.07692307,len / 1.14754098},	(650,610)
//		{len / 1.07692307,len / 1.09375},		(650,640)
//		{len / 1.18644067,len / 1.09375},		(590,640)
//		{len / 1.18644067,len / 1.14754098},	(590,610)
//		{len / 1.15702479,len / 1.14754098},	(605,610)
//		{len / 1.12903225,len / 1.18644067},	(620,590)
//	};
//	setcolor(EGERGB(117, 59, 19));
//	ege_drawpoly(numPoints12, polyPoints12);
//}


void DrawHouse()
{
	//右旋钮橙色房子
	ege_enable_aa(true);
	int numPoints12 = 8;
	double x2 = len / 1.12903225;
	double y2 = len / 1.12;
	ege_point  polyPoints12[8] = {
		{(len / 1.12903225 - x2) * cos(PI / 180.0 * jiaodu2) - (len / 1.18644067 - y2) * sin(PI / 180.0 * jiaodu2) + x2, (len / 1.12903225 - x2) * sin(PI / 180.0 * jiaodu2) + (len / 1.18644067 - y2) * cos(PI / 180.0 * jiaodu2) + y2},
		{(len / 1.10236220 - x2) * cos(PI / 180.0 * jiaodu2) - (len / 1.14754098 - y2) * sin(PI / 180.0 * jiaodu2) + x2, (len / 1.10236220 - x2) * sin(PI / 180.0 * jiaodu2) + (len / 1.14754098 - y2) * cos(PI / 180.0 * jiaodu2) + y2},
		{(len / 1.07692307 - x2) * cos(PI / 180.0 * jiaodu2) - (len / 1.14754098 - y2) * sin(PI / 180.0 * jiaodu2) + x2, (len / 1.07692307 - x2) * sin(PI / 180.0 * jiaodu2) + (len / 1.14754098 - y2) * cos(PI / 180.0 * jiaodu2) + y2},
		{(len / 1.07692307 - x2) * cos(PI / 180.0 * jiaodu2) - (len / 1.09375 - y2) * sin(PI / 180.0 * jiaodu2) + x2, (len / 1.07692307 - x2) * sin(PI / 180.0 * jiaodu2) + (len / 1.09375 - y2) * cos(PI / 180.0 * jiaodu2) + y2},
		{(len / 1.18644067 - x2) * cos(PI / 180.0 * jiaodu2) - (len / 1.09375 - y2) * sin(PI / 180.0 * jiaodu2) + x2, (len / 1.18644067 - x2) * sin(PI / 180.0 * jiaodu2) + (len / 1.09375 - y2) * cos(PI / 180.0 * jiaodu2) + y2},
		{(len / 1.18644067 - x2) * cos(PI / 180.0 * jiaodu2) - (len / 1.14754098 - y2) * sin(PI / 180.0 * jiaodu2) + x2, (len / 1.18644067 - x2) * sin(PI / 180.0 * jiaodu2) + (len / 1.14754098 - y2) * cos(PI / 180.0 * jiaodu2) + y2},
		{(len / 1.15702479 - x2) * cos(PI / 180.0 * jiaodu2) - (len / 1.14754098 - y2) * sin(PI / 180.0 * jiaodu2) + x2, (len / 1.15702479 - x2) * sin(PI / 180.0 * jiaodu2) + (len / 1.14754098 - y2) * cos(PI / 180.0 * jiaodu2) + y2},
		{(len / 1.12903225 - x2) * cos(PI / 180.0 * jiaodu2) - (len / 1.18644067 - y2) * sin(PI / 180.0 * jiaodu2) + x2, (len / 1.12903225 - x2) * sin(PI / 180.0 * jiaodu2) + (len / 1.18644067 - y2) * cos(PI / 180.0 * jiaodu2) + y2},
	};
	setcolor(EGERGB(117, 59, 19));
	ege_drawpoly(numPoints12, polyPoints12);
}

void DrawMinHouse()
{
	//轮盘上的小房子
	ege_enable_aa(true);
	int numPoints13 = 8;
	double x2 = len / 2.0;
	double y2 = len / 2.0;
	ege_point  polyPoints13[8] = {
		{(len / 2.12121212 - x2) * cos(PI / 180.0 * jiaodu3) - (len / 7.0 - y2) * sin(PI / 180.0 * jiaodu3) + x2, (len / 2.12121212 - x2) * sin(PI / 180.0 * jiaodu3) + (len / 7.0 - y2) * cos(PI / 180.0 * jiaodu3) + y2},//330,100
		{(len / 1.89189189 - x2) * cos(PI / 180.0 * jiaodu3) - (len / 7.0 - y2) * sin(PI / 180.0 * jiaodu3) + x2, (len / 1.89189189 - x2) * sin(PI / 180.0 * jiaodu3) + (len / 7.0 - y2) * cos(PI / 180.0 * jiaodu3) + y2},//370,100
		{(len / 1.89189189 - x2) * cos(PI / 180.0 * jiaodu3) - (len/ 5.83333333 - y2) * sin(PI / 180.0 * jiaodu3) + x2, (len / 1.89189189 - x2) * sin(PI / 180.0 * jiaodu3) + (len/ 5.83333333 - y2) * cos(PI / 180.0 * jiaodu3) + y2},//370,120
		{(len / 1.97183098 - x2) * cos(PI / 180.0 * jiaodu3) - (len/ 5.83333333 - y2) * sin(PI / 180.0 * jiaodu3) + x2, (len / 1.97183098 - x2) * sin(PI / 180.0 * jiaodu3) + (len / 5.83333333 - y2) * cos(PI / 180.0 * jiaodu3) + y2},//355,120
		{(len / 2.0 - x2) * cos(PI / 180.0 * jiaodu3) - (len / 5.38461538 - y2) * sin(PI / 180.0 * jiaodu3) + x2, (len / 2.0 - x2) * sin(PI / 180.0 * jiaodu3) + (len / 5.38461538 - y2) * cos(PI / 180.0 * jiaodu3) + y2},//350,130
		{(len / 2.02898550 - x2) * cos(PI / 180.0 * jiaodu3) - (len/ 5.83333333 - y2) * sin(PI / 180.0 * jiaodu3) + x2, (len / 2.02898550 - x2) * sin(PI / 180.0 * jiaodu3) + (len / 5.83333333 - y2) * cos(PI / 180.0 * jiaodu3) + y2},//345,120
		{(len / 2.12121212 - x2) * cos(PI / 180.0 * jiaodu3) - (len / 5.83333333 - y2) * sin(PI / 180.0 * jiaodu3) + x2, (len / 2.12121212 - x2) * sin(PI / 180.0 * jiaodu3) + (len / 5.83333333 - y2) * cos(PI / 180.0 * jiaodu3) + y2},//330,120
		{(len / 2.12121212 - x2) * cos(PI / 180.0 * jiaodu3) - (len / 7.0 - y2) * sin(PI / 180.0 * jiaodu3) + x2, (len / 2.12121212 - x2) * sin(PI / 180.0 * jiaodu3) + (len / 7.0 - y2) * cos(PI / 180.0 * jiaodu3) + y2},//330,100
	};
	setcolor(EGERGB(117, 59, 19));
	ege_drawpoly(numPoints13, polyPoints13);
}


void DrawCenterDisk()
{
	//中心圆盘
	ege_enable_aa(true);
	setfillcolor(EGERGB(14, 14, 14));
	ege_fillellipse(len / 3.88888888, len / 3.88888888, len / 2.058823520, len / 2.058823520);
	//中心矩形
	ege_enable_aa(true);
	int numPoints13 = 4;
	double x2 = len / 2.0;
	double y2 = len / 2.0;
	ege_point  polyPoints13[4] = {
		{(len / 3.18181818 - x2) * cos(PI / 180.0 * jiaodu1) - (len / 2.1875 - y2) * sin(PI / 180.0 * jiaodu1) + x2, (len / 3.18181818 - x2) * sin(PI / 180.0 * jiaodu1) + (len / 2.1875 - y2) * cos(PI / 180.0 * jiaodu1) + y2},
		{(len / 1.45833333 - x2) * cos(PI / 180.0 * jiaodu1) - (len / 2.1875 - y2) * sin(PI / 180.0 * jiaodu1) + x2, (len / 1.45833333 - x2) * sin(PI / 180.0 * jiaodu1) + (len / 2.1875 - y2) * cos(PI / 180.0 * jiaodu1) + y2},
		{(len / 1.45833333 - x2) * cos(PI / 180.0 * jiaodu1) - (len / 1.84210526 - y2) * sin(PI / 180.0 * jiaodu1) + x2, (len / 1.45833333 - x2) * sin(PI / 180.0 * jiaodu1) + (len / 1.84210526 - y2) * cos(PI / 180.0 * jiaodu1) + y2},
		{(len / 3.18181818 - x2) * cos(PI / 180.0 * jiaodu1) - (len / 1.84210526 - y2) * sin(PI / 180.0 * jiaodu1) + x2, (len / 3.18181818 - x2) * sin(PI / 180.0 * jiaodu1) + (len / 1.84210526 - y2) * cos(PI / 180.0 * jiaodu1) + y2},
	};

	/*{220, 320},
	{ 480,320 },
	{ 480,380 },
	{ 220,380 },
	
			{len / 3.18181818,len / 2.1875},
		{len / 1.45833333,len / 2.1875},
		{len / 1.45833333,len / 1.84210526},
		{len / 3.18181818,len / 1.84210526},
		
	*/

	setfillcolor(BLACK);
	ege_fillpoly(numPoints13, polyPoints13);
	//中心条纹

}

int positionOffset(int key)//键盘移动轮盘
{
	int dx = 0, dy = 0;

	switch (key) {
	case 'A': case key_left:	dx = 1;	break;	//左移
	
	case 'D': case key_right:	dx = -1;	break;	//右移
	
	default:  break;	//其他键不移动
	}
	return dx;
}

void isMouse()//判断旋钮是否被操纵
{
	Button button1 = { len / 8.58895705,len / 1.12269446,len / 15.55555555, false };
	Button button2 = { len / 1.13177041,len / 1.12269446,len / 15.55555555, false };
	int xLeftPress = -1, yLeftPress = -1;
	bool flag_pressButton = false;
	if (mousemsg()) {
		mouse_msg msg = getmouse();
		// 处理鼠标左键点击
		if (msg.is_left()) {
			if (msg.is_down()) {
				xLeftPress = msg.x;
				yLeftPress = msg.y;

				// 如果鼠标在按钮区域按下，设置鼠标为按下状态，标记鼠标按下按钮
				if (isPressOnButton1(&button1, xLeftPress, yLeftPress)) {
					flag_pressButton = true;
					button1.press = true;
					jiaodu1 -= 5;//旋转5度
				}
				if (isPressOnButton2(&button2, xLeftPress, yLeftPress)) {
					flag_pressButton = true;
					button2.press = true;
					jiaodu2 += 5;
					jiaodu3 += 5;
				}
			}
			else {
				//鼠标按下按钮，抬起时触发点击事件
				if (flag_pressButton) {
					flag_pressButton = false;
					// 恢复按钮为非按下状态
					button1.press = false;
					button2.press = false;
				}

			}
		}
		if (msg.is_right()) {
			if (msg.is_down()) {
				xLeftPress = msg.x;
				yLeftPress = msg.y;

				// 如果鼠标在按钮区域按下，设置鼠标为按下状态，标记鼠标按下按钮
				if (isPressOnButton1(&button1, xLeftPress, yLeftPress)) {
					flag_pressButton = true;
					button1.press = true;
					jiaodu1 += 5;//旋转5度
				}
				if (isPressOnButton2(&button2, xLeftPress, yLeftPress)) {
					flag_pressButton = true;
					button2.press = true;
					jiaodu2 -= 5;
					jiaodu3 -= 5;
				}
			}
			else {
				//鼠标按下按钮，抬起时触发点击事件
				if (flag_pressButton) {
					flag_pressButton = false;
					// 恢复按钮为非按下状态
					button1.press = false;
					button2.press = false;
				}

			}
		}
	}
}

void isKey() //是否对轮盘进行操作
{
	int dx = 0;
	bool keyIsPressed[256] = { false };
	while (kbmsg()) {
		key_msg msg = getkey();
		if (msg.msg == key_msg_down) {
			//按键按下，记录按键已变为按下状态
			dx= positionOffset(msg.key);
			j = j + dx;
			jiaodu1 = jiaodu1 - 2 * dx;
			jiaodu2 = jiaodu2 - 2 * dx;
			jiaodu3 = jiaodu3 - 2 * dx;
			keyIsPressed[msg.key] = true;
		}
		else if (msg.msg == key_msg_up) {
			// 按键抬起，记录按键已变为松开状态
			keyIsPressed[msg.key] = false;
		}
	}
}

int main(void)
{

	//int j = 0;
	Init();
	InitNumber();
	ege_enable_aa(true);
	setlinewidth(3.0);
	setbkmode(TRANSPARENT);

	while (true) {
		isKey();//是否对轮盘进行操作
		
		setcolor(EGEARGB(0xFF, 220, 220, 220));
		DrawSecLine(60 - j);//内刻度

		//j -= 1;
		//jiaodu1 += 0.1;
		//jiaodu2 += 0.1;

		DrawCompass();//圆形罗盘
		
		//DisplaymMouseCoordinates();//显示鼠标坐标

		DrawCenterDisk();//中心圆盘
		DrawMinHouse();//轮盘上的小房子
		DrawScale();//外刻度
		DrawPointer();//指针
		DrawPlane();//飞机
		DrawMAU();//MAU红色字块
		DrawGS();//GS红色字块
		DrawInnerborder();//内边框
		DrawBoundary();//屏幕边界
		DrawMargin();//外边框第一次
		DrawFill1();//背景区域填充
		DrawBENDIXIKING();//打印字母
		DrawMargin();//外边框第二次
		DrawWhiteGS();//白色GS
		DrawKnob();//旋钮

		//DrawFill2();//按钮区域填充

		DrawButtonArrows();//左旋钮黄色箭头
		DrawHouse();//右旋钮橙色房子

		isMouse();//判断旋钮是否被操纵

		//帧率调节
		delay_fps(30);
		//Sleep(50);
		cleardevice();
	}
	getch();
	closegraph();

	return 0;
}